let fs = require('fs');
let writeStream = require('./myWriteStream')

// let ws = fs.createWriteStream('./b.txt', {
//     flags: 'w',
//     encoding: 'utf8',
//     fd: null,
//     mode: 0o666,
//     autoClose: true,
//     start: 0,
//     highWaterMark: 3
// });

let ws = new writeStream('./b.txt', { 
    flags: 'w',
    encoding: 'utf8',
    fd: null,
    mode: 0o666,
    autoClose: true,
    start: 0,
    highWaterMark: 3
});


ws.on('drain', function() {
    console.log('抽干')
})

// let flag = ws.write('a', 'utf8', function() {
//     console.log('写入成功')
// })

let i = 9;

function write() {
    flag = true;
    while (flag && i>= 0) {
        flag = ws.write(i-- + '')
    }
}

write();

ws.end('close')

console.log(flag);

